package com.wendu.oa.api.info;


import com.wendu.oa.common.Result;
import com.wendu.oa.common.page.PageParam;
import com.wendu.oa.dto.EmployeeDto;
import com.wendu.oa.model.Employee;
import com.wendu.oa.service.info.DepService;
import com.wendu.oa.service.info.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/info/emp")
public class EmpController {


//    void kkk(EmployeeDto employeeDto){
//
//        StringBuilder where = new StringBuilder("select * from xxx where 1=1 ");
//        List<Object> paramList = new ArrayList<>();
//
//        if(employeeDto != null){
//
//            if(employeeDto.getD_id() != null && !employeeDto.getD_id().equals("")){
//                where.append(" and e_id like ? ");
//                paramList.add("%"+employeeDto.getE_id()+"%");
//            }
//
//            if(employeeDto.getD_id() != null && !employeeDto.getD_id().equals("")){
//                where.append(" and e_id like ? ");
//                paramList.add("%"+employeeDto.getE_id()+"%");
//            }
//
//        }
//
//        //........
//
//    }

    @Autowired
    private EmpService empService;

    @Autowired
    private DepService depService;

    //get请求无法接收请求体，只能接收路径变量和查询字符串（Query String）
    @GetMapping("")
    public Result empList(EmployeeDto employeeDto){


       //List<Employee> list = empService.getEmpList(employeeDto);
        Map<String,Object> page = empService.getEmpPage(employeeDto);

       return Result.OK(page);
    }

    @GetMapping("/deps")
    public Result allDepList(){
        return Result.OK(depService.getDepList());
    }

    @PostMapping("")
    public Result addEmp(@RequestBody EmployeeDto employeeDto){
        empService.addEmp(employeeDto);
        return Result.OK();
    }

    @PutMapping("")
    public Result updEmp(@RequestBody EmployeeDto employeeDto){
        empService.updateEmp(employeeDto);
        return Result.OK();
    }

    @DeleteMapping("/{eid}")
    public Result delEmp(@PathVariable String eid){
        empService.deleteEmp(eid);
        return Result.OK();
    }

    @DeleteMapping("")
    public Result delMultiEmp(@RequestBody String[] eids){
        empService.deleteEmp(eids);
        return Result.OK();
    }

    @PutMapping("/leader/{eid}")
    public Result setLeader(@PathVariable String eid){
        empService.setLeader(eid);
        return Result.OK();
    }

    @PutMapping("/user/{eid}")
    public Result createUser(@PathVariable String eid){
        empService.createUser(eid);
        return Result.OK();
    }


}
